﻿using System;
using System.Collections.Generic;
using System.Text;


namespace Mine
{

   public  enum MineType { Linear=0, Circular=1, Complete=2,Last=3 }
    public delegate void Simulator(object M);

    public interface IMine
    {
        void Print(System.IO.TextWriter sw);
        void BuildMine(int MaxStone, int K, int N, MineType mt);
        List<Simulator> Simulation
        {
            get;
        }
    }

    class Mine<StationType>:IMine
        where StationType:IStation, new()
    {
        private StationType[] StationTypes;//Graf csucsai
        List<Track> Tracks;//Graf elei

        public List<Simulator> Simulation
        {
            get
            {
                List<Simulator> SL = new List<Simulator>();
                foreach (Track t in Tracks)
                {
                    SL.Add(new Simulator(t.Simulation ));
                }
                return SL;
            }
        }

        public void BuildMine(int MaxStone, int K, int N,MineType mt)
        {
            Tracks = new List<Track>();
            StationTypes = new StationType[N];
            for (int i = 0; i < N; i++)
            {
                StationTypes[i] = new StationType();
                StationTypes[i].Initialize(i, K);
                StationTypes[i].ID = i;
            }

            if (mt == MineType.Circular || mt == MineType.Linear)
            {
                for (int i = 1; i < N; i++)
                {
                    //Egymasmeletti StationTypeokat osszekotunk
                    Tracks.Add(new Track(StationTypes[i], StationTypes[i - 1], MaxStone));
                }
                if (mt == MineType.Circular)
                {
                    //elso es utolso StationTypet osszekotjuk
                    Tracks.Add(new Track(StationTypes[0],StationTypes[StationTypes.Length-1], MaxStone));
                }
            }
            if (mt == MineType.Complete)
            {
                for (int i = 0; i < N; i++)
                {
                    for (int j = 0; j < i; j++)
                    {
                        Tracks.Add(new Track(StationTypes[i],StationTypes[j], MaxStone));
                    }
                }
            }
        }
        public void Print(System.IO.TextWriter sw)
        {
            long TS = 0;
            for (int i = 0; i < StationTypes.Length; i++)
            {
                sw.WriteLine(string.Format("Station:{0:000} Wagon:{1:000} Stones:{2:000}", i, StationTypes[i].Wagon, StationTypes[i].Stones));
                TS += StationTypes[i].Stones;
            }
            sw.WriteLine("Total Stones:{0}", TS);
            foreach (Track t in Tracks)
            {
                sw.WriteLine("Track from {0:000} to {1:000} Consumption:{2:00000.00}", t.IDa, t.IDb, t.Consuption);
            }
        }
    }
}
